package com.lrj.datastructure.calendar;

//蔡勒公式:https://zhidao.baidu.com/question/9491607.html
//原理：https://www.zhihu.com/question/42879877
public class ZellerCalendar extends Calendar{
    @Override
    protected int getWeek() {
        int y = year;
        int c = year;
        int m = month;
        int d = 1;

        if (m == 1 || m == 2) {
            m += 12;
            y --;
        }

        c = y / 100;
        y = y % 100;

        System.out.println(String.format("y = %d, c = %d, m = %d, d = %d", y, c, m, d));

        int sum = y + y / 4 + c / 4 - 2 * c + ( 26 * (m + 1 ) / 10) + d - 1;

        System.out.println("sum = " + sum);

        return sum % 7;
    }
}
